package skean.apclient;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class ClientReceiver extends BroadcastReceiver {
	public static final String ACTION_START = "skean.apclient.ACTION_START";
	public static final String ACTION_SCAN = "skean.apclient.ACTION_SCAN";

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(intent.ACTION_BOOT_COMPLETED)
			|| intent.getAction().equals(ACTION_START)) {
			Intent nIntent = new Intent(context, BSInfoService.class);
			context.startService(nIntent);
			AlarmManager alarmManager = (AlarmManager) context
				.getSystemService(context.ALARM_SERVICE);
			Intent mIntent = new Intent(ACTION_SCAN);
			PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, mIntent, 0);
			alarmManager.cancel(pIntent);
			alarmManager.setRepeating(alarmManager.RTC_WAKEUP, System.currentTimeMillis(),
				10 * 1000, pIntent);
		}
		else if (intent.getAction().equals(ACTION_SCAN)) {
			Toast.makeText(context, "扫描wifi中", Toast.LENGTH_LONG).show();
			Intent mIntent = new Intent(context, ScanService.class);
			context.startService(mIntent);
		}
	}
}
